package com.beerbear.consumer.config.listener;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @Author: Beer Bear
 * @Description: 话题模式的发布订阅消息发送接收
 * @Date: 2021/9/3 14:04
 */
@Component
public class SpringRabbitMQListenerForTopic {
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "topic.queue1"),
            exchange = @Exchange(name = "topic",type = ExchangeTypes.TOPIC),
            key = {"china.#"})
    )
    public void listenDirectQueue1(String msg) {
        System.out.println("接收到来自中国的所有消息：" + msg);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "topic.queue2"),
            exchange = @Exchange(name = "topic",type = ExchangeTypes.TOPIC),
            key = {"#.news"})
    )
    public void listenDirectQueue2(String msg) {
        System.out.println("接收到所有国家的新闻：" + msg);
    }
}
